Switch ObjectName to GString
authorFelix Krull <f_krull@gmx.de>
Tue, 21 May 2019 18:29:42 +0000 (20:29 +0200)
committerColin Walters <walters@verbum.org>
Fri, 6 May 2022 16:53:53 +0000 (12:53 -0400)
rust-bindings/rust/src/object_name.rs

index 25635ec7c8ad10ec8122a05056040471d1637098..5d6144906b3a8a3b14589d4551d1569f943996ea 100644 (file)
@@ -1,6 +1,7 @@
 use functions::{object_name_deserialize, object_name_serialize, object_to_string};
 use glib;
 use glib::translate::*;
+use glib::GString;
 use glib_sys;
 use ostree_sys;
 use std::fmt::Display;
@@ -17,8 +18,7 @@ fn hash_object_name(v: &glib::Variant) -> u32 {
 #[derive(Eq, Debug)]
 pub struct ObjectName {
     variant: glib::Variant,
-    // TODO: can I store a GString here?
-    checksum: String,
+    checksum: GString,
     object_type: ObjectType,
 }
 
@@ -27,12 +27,12 @@ impl ObjectName {
         let deserialize = object_name_deserialize(&variant);
         ObjectName {
             variant,
-            checksum: deserialize.0.into(),
+            checksum: deserialize.0,
             object_type: deserialize.1,
         }
     }
 
-    pub fn new<S: Into<String>>(checksum: S, object_type: ObjectType) -> ObjectName {
+    pub fn new<S: Into<GString>>(checksum: S, object_type: ObjectType) -> ObjectName {
         let checksum = checksum.into();
         let variant = object_name_serialize(checksum.as_str(), object_type).unwrap();
         ObjectName {
@@ -43,18 +43,16 @@ impl ObjectName {
     }
 
     pub fn checksum(&self) -> &str {
-        self.checksum.as_ref()
+        self.checksum.as_str()
     }
 
     pub fn object_type(&self) -> ObjectType {
         self.object_type
     }
 
-    // TODO: return GString
-    pub fn name(&self) -> String {
+    pub fn name(&self) -> GString {
         object_to_string(self.checksum(), self.object_type())
             .expect("type checks should make this safe")
-            .into()
     }
 }